//
//  NSArray+BZHelper.m
//  BZFoundation
//
//  Created by 郭艺伟 on 2017/9/30.
//  Copyright © 2017年 郭艺伟. All rights reserved.
//

#import "NSArray+BZHelper.h"

@implementation NSArray (BZHelper)
- (NSArray *)bz_shuffleArray {
    NSMutableArray *results = [NSMutableArray arrayWithArray:self];
    NSUInteger count = [results count];
    // See http://en.wikipedia.org/wiki/Fisher–Yates_shuffle
    if (count > 1) {
        for (NSUInteger i = count - 1; i > 0; --i) {
            [results exchangeObjectAtIndex:i withObjectAtIndex:arc4random_uniform((int32_t)(i + 1))];
        }
    }
    return [results copy];
}

- (NSArray *)bz_reverseArray {
    if ([self count] == 0 || [self count] == 1) {
        return self;
    }
    return [[self reverseObjectEnumerator] allObjects];
}
@end
